#include <boost/exception/all.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/shared_array.hpp>
#include <exception>
#include <string>
#include <iostream>

typedef boost::error_info<struct tag_errmsg0, std::string> errmsg_info;

class allocation_failed: public boost::exception, public std::exception
//class allocation_failed:  public std::exception
{
public:
    allocation_failed(std::size_t size)
        : m_what("allocation of " + boost::lexical_cast<std::string>(size) + " bytes failed")
    {
    }
    virtual const char* what() const throw()
    {
        return m_what.c_str();
    }
private:
    std::string m_what;
};

boost::shared_array<char> allocate(std::size_t size)
{
    if(size > 1000)
        /*throw allocation_failed(size);*/
        BOOST_THROW_EXCEPTION(allocation_failed(size) );
    return boost::shared_array<char>(new char[size]);
}

void save_configuration_data()
{
    try {
        boost::shared_array<char> a = allocate(2000);
    }
    catch (boost::exception &e) {
        e << errmsg_info("saving configuration data failed\n");
        throw;
    }
}

int main()
{
    try {
        save_configuration_data();
    }
    catch (boost::exception &e) {
        std::cerr << boost::diagnostic_information(e);
        //std::cerr << *boost::get_error_info<errmsg_info>(e);
    }
}